import {createStore} from 'vuex'
import axios from 'axios'
import auth from '../sso/Authing'
import router from './index'
import { Dialog } from 'vant';
const store = createStore({
    state () {
      return {
        count:null, 
        auth:auth,
        router:router,
      }
    },
    mutations: {
      getBadge:function(state){
        axios.get("extra/getTotal.php").then(response=>{
          state.count=response.data[0]['count']
        })
      },
      init:async function(state){
        let response=await state.auth.trackSession()
        console.log(response)
        if(response.session===null){
          Dialog.confirm({
            title:"登录",
            message:"请先登录"
          })
          .then(()=>{
            state.auth.login()
          })
          .catch(()=>{
            state.router.push({name:"HomePage"})
          })
        }
      },
    }
  })
export default store